import java.util.Scanner;

public class ATM {

    //账号
    public static String cardNo="123456";
    //密码
    public  static String oldPwd="111111";
    //存款金额
    public static double money=1000;

     public static Scanner scanner = new Scanner(System.in);


    public static void main(String[] args) {
        while(true){
            //记录登录的次数，0 则表示账号被锁定了
             boolean islogin =  login();
            //显示操作界面
            showMenu(islogin);
        }
    }

    public static boolean login(){
        int num=3;
        while(true){

            System.out.println("欢迎XXX银行：");
            System.out.println("请输入卡号(6位)：");
            cardNo = scanner.nextLine();
            System.out.println("请输入密码(6位)：");
            String pwd = scanner.nextLine();
            //判断账号是否被锁定
            if(num!=0){
                if(cardNo.equals("123456") && pwd.equals(oldPwd)  ){
                    ///System.out.println("ok");
                    //设置登录成功
                    return true;
                }else{
                    //System.out.println("no");
                    System.out.println("用户名或者密码错误，你还有"+(num-1)+"次机会");
                    num--;
                }
            }else{
                System.out.println("账号已被锁定，请联系工作人员");
            }
        }
    }

    public static void showMenu(boolean islogin){
        if(islogin){
            System.out.println("欢迎您:"+cardNo);
            System.out.println("显示操作界面--------------------");
            //记录是否进行操作处理
            boolean isoperation=true;
            while(isoperation){
                System.out.println("1: 查询余额   2: 存款  3: 取款  4 修改密码 5 注销登录" );
                System.out.println("请输入您的选择：");
                //获得输入的操作
                int choose = scanner.nextInt();
                switch(choose){
                    case 1:
                        System.out.println("查询余额:你的余额为"+money+"元");
                        break;
                    case 2:
                        System.out.println("存款：");
                        Scanner scaner = new Scanner(System.in);
                        System.out.println("请输入你的存款金额：");
                        int cun = scaner.nextInt();
                        money+=cun;
                        System.out.println("存款成功，余额："+money);
                        break;
                    case 3:
                        System.out.println("取款------");
                        Scanner scaner1 = new Scanner(System.in);
                        System.out.println("请输入你的存款金额：");
                        int qu = scaner1.nextInt();
                        if(qu<money){
                            money-=qu;
                            System.out.println("取款成功，余额："+money);
                        }else{
                            System.out.println("余额不足：多努力");
                        }

                        break;
                    case 4:
                        System.out.println("修改密码");
                        System.out.println("请输入原密码：");
                        Scanner scaner2 = new Scanner(System.in);
                        String pwd = scaner2.nextLine();
                        if(pwd.equals(oldPwd)){

                            while(true){
                                System.out.println("请输入新密码：");
                                String newPwd_1 = scaner2.nextLine();
                                System.out.println("请确认密码：");
                                String newPwd_2 = scaner2.nextLine();
                                if(newPwd_1.equals(newPwd_2)){
                                    System.out.println("修改成功");
                                    oldPwd=newPwd_1;
                                    break;
                                }else{
                                    System.out.println("两次输入的密码不一致");
                                }
                            }


                        }else{
                            System.out.println("密码输入错误");
                        }

                        break;
                    case 5:
                        System.out.println("注销登录");
                        isoperation=false;
                        break;
                    default:
                        System.out.println("请输入0-4的值");
                }
            }
        }
    }
}
